﻿using System.Collections;
using FairyGUI;

/// <summary>
/// 离开按钮
/// </summary>
public class UIGameLeave : UIPopupWindow {
	
	public UIGameLeave()
	{
		// 加载界面
		base.Init(UIPackage.CreateObject("游戏界面", "解散房间界面").asCom);

		// 初始化关闭按钮
		GButton closeBtn = uiComp.GetChild("关闭按钮").asButton;
		closeBtn.onClick.Add(() => {
			_Close();
		});

		// 解散房间
		GButton leaveBtn = uiComp.GetChild("发送请求").asButton;
		leaveBtn.onClick.Add(() => {
			Hashtable reqArgs = new Hashtable ();
			reqArgs ["uid"] = DataKernel.inst.userInfo.uid;
			reqArgs ["roomId"] = GameDataKernel.inst.roomId;

			NetIOController.inst.SendMessage (
				new IOMessage(
					IOCmds.CMSG_PLAYER_REQ_DESTROY_ROOM, 
					IOStates.STATE_OK, 
					new HashtableEx(reqArgs)));

			_Close ();
		});
	}

	public void _Close() {
		DebugInfo.Log("关闭解散房间界面");

		AudioController.inst.PlayUIClickEffect();
		uiComp.RemoveFromParent();
		uiComp.Dispose();
		base.Close();
	}

	/// <summary>
	/// 弹出窗口
	/// </summary>
	public static void Popup()
	{
		DebugInfo.Log("打开解散房间界面");
		UIRootController.inst.PopupWindow(new UIGameLeave());
	}
}

